package com.plusjun.search.controller;

import com.plusjun.search.service.MallSearchService;
import com.plusjun.search.vo.SearchParamVO;
import com.plusjun.search.vo.SearchResultVO;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

@Controller
public class SearchController {
    @Resource
    MallSearchService mallSearchService;

    @GetMapping(value = "/list.html")
    public String list(SearchParamVO param, Model model, HttpServletRequest request){
        String queryString = request.getQueryString();
        param.set_queryString(queryString);
        // 根据传递爱的页码的查询参数，去es中检索商品
        SearchResultVO result = mallSearchService.search(param);
        model.addAttribute("result",result);
        return "list";
    }
}
